home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / switchCallbacks.c < prev    next >
Encoding:
Text File  |  2001-07-10  |  1.4 KB  |  64 lines  |  [TEXT/CWIE]

  1. // #include "gltron.h"
  2. #include "system.h"
  3. #include "callbacks.h"
  4.  
  5. callbacks *last_callback = NULL;
  6. callbacks *current_callback = NULL;
  7.  
  8. void switchCallbacks(callbacks *new) {
  9.   last_callback = current_callback;
  10.   current_callback = new;
  11.  
  12.   if(last_callback != NULL)
  13.     (last_callback->exit)(); /* give them the chance to quit */
  14.  
  15.   SystemRegisterCallbacks(new);
  16.  
  17.   /* lasttime = SystemGetElapsedTime(); */
  18.  
  19.  /* printf("callbacks registred\n"); */
  20.   (new->init)();
  21.   (new->initGL)();
  22.   /* printf("callback init's completed\n"); */
  23. }
  24.   
  25. void updateCallbacks() {
  26.   /* called when the window is recreated */
  27.   SystemRegisterCallbacks(current_callback);
  28.  
  29.   (current_callback->initGL)();
  30. }
  31.  
  32. void restoreCallbacks() {
  33.   if(last_callback == NULL) {
  34.     fprintf(stderr, "no last callback present, exiting\n");
  35.     exit(1);
  36.   }
  37.   current_callback = last_callback;
  38.  
  39.   SystemRegisterCallbacks(current_callback);
  40.   
  41.   /* lasttime = SystemGetElapsedTime(); */
  42.  
  43.   fprintf(stderr, "restoring callbacks\n");
  44. }
  45.  
  46. void chooseCallback(char *name) {
  47.   /* maintain a table of names of callbacks */
  48.   /* lets hardcode the names for all known modes in here */
  49.  
  50.   /* TODO(3): incorporate model stuff */
  51.   /*
  52.     if(strcmp(name, "chooseModel") ==  0) {
  53.     fprintf(stderr, "change callbacks to chooseModel\n");
  54.     switchCallbacks(&chooseModelCallbacks);
  55.     }
  56.   */
  57.   if(strcmp(name, "gui") == 0) {
  58.     /* fprintf(stderr, "change callbacks to gui\n"); */
  59.     switchCallbacks(&guiCallbacks);
  60.   }
  61. }
  62.  
  63.  
  64.